package aes;

import java.io.File;

import server.gui.Server_GUI;
import sharedspace.User;
import client.gui.Client_GUI;
import client.gui.GUI_Create_Manual_Test;
import database.JDBC;
import fit.ActionFixture;

public class CreateManualTestTests extends ActionFixture{
	
	Client_GUI client_GUI;
	Server_GUI server_GUI;
	User user;
	GUI_Create_Manual_Test gui_Create_Manual_Test;
	//run server
	public void startServer(String password)
	{
		server_GUI = new Server_GUI();
		server_GUI.getUserTextField().setText("root");
		server_GUI.getPWTextField().setText(password);
		server_GUI.getConnectBtn().doClick();
	}
	//run client with Teacher user
	public void startClient() throws Exception
	{
		client_GUI = new Client_GUI();
		client_GUI.connect();
		user = new User();
		user.setUserID("036855336");
		user.setUserFirstName("Maya");
		user.setUserLastName("Gal");
		user.setUserLogged(true);
		user.setUserPermission(2);
		user.setUserStatus("Active");		
	}
	//run manual test gui
	public void startCreateManualTest()
	{
		gui_Create_Manual_Test = new GUI_Create_Manual_Test(client_GUI, user);
	}
	//add path for file
	public void addManualTestFile(String path)
	{
		File file = new File(path);
		gui_Create_Manual_Test.setFileTeacher(file);
	}
	//add duration of test
	public void addManualTestDuration(String duration)
	{
		gui_Create_Manual_Test.setDuration(duration);
	}
	//select subject
	public void selectSubject(int index)
	{	
		gui_Create_Manual_Test.comboBoxTeacherSubject.setSelectedIndex(index);
	}
	//select course
	public void selectCourse(int index)
	{
		gui_Create_Manual_Test.comboBoxCourse.setSelectedIndex(index);
	}
	//check if user choose for subject form combobox
	public boolean isSubjectSelected()
	{
		int top = gui_Create_Manual_Test.comboBoxTeacherSubject.getItemCount();
		return (gui_Create_Manual_Test.comboBoxTeacherSubject.getSelectedIndex()>0 && gui_Create_Manual_Test.comboBoxTeacherSubject.getSelectedIndex()<top);
	}
	//check if user choose for course form combobox
	public boolean isCourseSelected()
	{
		int top = gui_Create_Manual_Test.comboBoxCourse.getItemCount();
		return (gui_Create_Manual_Test.comboBoxCourse.getSelectedIndex()>0 && gui_Create_Manual_Test.comboBoxCourse.getSelectedIndex()<top);
	}
	//insert manual test to database
	public void insertManualTestToDb()
	{
		gui_Create_Manual_Test.getBtnCreate().doClick();
	}
	//check if manual test inserted to database
	public boolean isInsertToDb()
	{
		return JDBC.existStatment("'"+gui_Create_Manual_Test.getTestID()+"'", "t.testID", "aes.test t");
	}
	//check extension of file
	public boolean checkPath()
	{
		return gui_Create_Manual_Test.isValidFileExtension();
	}
	//check duration of test
	public boolean checkDuration()
	{
		return gui_Create_Manual_Test.cheackDuration(gui_Create_Manual_Test.getDuration());
	}
	
	

}
